<?php
class ShareFavDelAction extends FrontendAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	public function execute()
	{
		$this->code 	= 0;
		$share_id 		= intval($this->context->post('share_id'));
		if (!$share_id > 0){
			$this->code 	= 105;
			return;
		}
		
		$shareService	= new BaseDbService('share');
		$shareInfo		= $shareService->get($share_id);
		if (!$shareInfo){
			$this->code 	= 105;
			return;
		}
		$collectService	= new BaseDbService('collect');
		$tmp	= $collectService->deleteRows(array('share_id'=>'eq:'.$share_id, 'user_id'=>'eq:'.$this->data['user']['id']));
		if ($tmp){
			$collect_num = $shareInfo['collect_num']-1;
			if ($collect_num <0)$collect_num = 0;
			$shareService->update($share_id, array('collect_num'=>$collect_num));
			
			//TODO 更新服务器被喜欢数量
			$this->data['share']['collect_num'] = $collect_num;
			$this->code 	= 100;
		}
		
	}
}
